% Determine the width of the narrow bar.
% ======================================
% The algorithm tries to fit the data with a quadratic function, local
% maximum is then considered the ideal width of the narrow bar:
%
%	y ~ a0 + a1*x + a2*x^2
%
%  |y1|   |1 x1 x1^2|
%  |y2|   |1 x2 x2^2| |a0|
%  |y3| = |1 x3 x3^2| |a1|
%  |..|   |.........| |a2|
%  |yn|   |1 xn xn^2|
%
function ys = regsq( fin )
	clear y;
	clear lfin;
	lfin=fin(1,1:(columns(fin)/2));
	y=lfin';   
	x=[1:rows(y)]';
	x2=x.*x;
	X(:,1)=ones(1,rows(x));
	X(:,2)=x;
	X(:,3)=x2;
	a=inv(X'*X)*(X'*y);
	for i=1:rows(y)
	   ys(i,1)=a(1,1)+a(2,1)*i+a(3,1)*i*i;
	endfor
end
	
